<template>
  <div class="view-wrapper">
    <el-card v-loading="loading" element-loading-text="获取数据中..."
             element-loading-spinner="el-icon-loading">
      <el-row :gutter="30">
        <el-col :span="20">
          <div class="role-item">
            <span class="role-label">
              <span class="required">*</span> 角色名称
            </span>
            <span class="role-label-text">{{person.name}}</span>
          </div>
          <div class="role-item">
            <span class="role-label">
              <span class="required">*</span> 角色描述
            </span>
            <span class="role-label-text">{{person.description}}</span>
          </div>
        </el-col>
      </el-row>
      <div class="role-block">
      </div>
      <el-row>
        <el-col :span="24">
          <el-table border stripe :data="person.permissions.data">
            <el-table-column width="250" label="权限分组" align="center">
              <template scope="scope">
                <el-checkbox>{{scope.row.name}}</el-checkbox>
              </template>
            </el-table-column>
            <el-table-column label="权限列表" align="center">
              <template scope="scope">
                <div class="checkbox-wrapper">
                  <el-checkbox>创建角色</el-checkbox>
                  <el-checkbox>创建角色232</el-checkbox>
                  <el-checkbox>创建12312角色</el-checkbox>
                  <el-checkbox>321</el-checkbox>
                  <el-checkbox>创建角色</el-checkbox>
                  <el-checkbox>创建角色232</el-checkbox>
                  <el-checkbox>创建12312角色</el-checkbox>
                  <el-checkbox>321</el-checkbox>
                </div>
              </template>
            </el-table-column>
          </el-table>
        </el-col>
      </el-row>
      <div class="divide-block"></div>
      <el-row>
        <el-col>
          <el-button type="primary" style="width: 100px;height: 35px" @click="doSave">保存</el-button>
          <el-button style="width: 100px;height: 35px" @click="goBack">返回</el-button>
        </el-col>
      </el-row>
    </el-card>
  </div>
</template>

<script>
  import roleApi from '@/api/role'
  export default {
    name: 'EditRole',
    data: () => ({
      loading: false,
      person: {}
    }),
    mounted () {
      var paramId = this.$route.params.roleId
      this.loading = true
      roleApi.getRoleById(paramId).then(res => {
        this.loading = false
        if (res.data.data) {
          this.person = Object.assign({}, this.person, res.data.data)
        }
      }, err => {
        this.loading = false
        this.$message({
          type: 'error',
          message: err.response.data.message
        })
      })
    },
    methods: {
      goBack () {
        this.$confirm('确定要取消编辑？', '提示', {
          dangerouslyUseHTMLString: true,
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$router.go(-1)
        })
      },
      doSave () {

      }
    }
  }
</script>

<style lang="scss" scoped>
  @import "../../assets/css/mixin";

  .role-item{
    padding-bottom: 15px;
    border-bottom: 1px solid #dcdfe6;
    margin-top: 15px;
    &:first-child{
      margin-top: 0px;
    }
  }

  .role-label{
    font-size: 16px;
    display: block;
    height: 30px;
    line-height: 30px;
    color: $font-color;
    margin-bottom: 10px ;
  }

  .role-label-text{
    font-size: 18px;
    margin-left: 40px;
    color: $font-color;
  }
  .role-block{
    margin-top: 30px;
    height: 50px;
    display: block;
    width:100%;
  }

  .checkbox-wrapper{
    float: left;
    text-align: left;
    padding-bottom: 10px;
  }
</style>
